package com.migration.model.migration.scripts;

import com.migration.model.migration.AbstractMigrationScript;

/**
 * 设备-步骤表(risk_device_step)迁移脚本
 */
public class A012_RiskDeviceStepMigrationScript extends AbstractMigrationScript {

    /**
     * 构造函数，初始化迁移配置
     */
    public A012_RiskDeviceStepMigrationScript() {
        super(
            "risk_device_step",
            "设备-步骤数据迁移",
            "多表关联",
            "risk_device_step",
            12
        );
    }

    /**
     * 生成迁移数据的SQL
     *
     * @return 迁移数据的SQL
     */
    @Override
    protected String generateMigrationSql() {
        return "INSERT INTO risk_device_step (\n" +
               "  id,\n" +
               "  department_id,\n" +
               "  device_id,\n" +
               "  step_id,\n" +
               "  deviation_id,\n" +
               "  cause_quantity,\n" +
               "  consequence_quantity\n" +
               ")\n" +
               "SELECT\n" +
               "  nr.id,\n" +
               "  n.tenant_id as department_id,\n" +
               "  nr.node_id as device_id,\n" +
               "  nr.linked_id as step_id,\n" +
               "  null,\n" +
               "  0,\n" +
               "  0\n" +
               "FROM\n" +
               "  risk_lunnan_test.ra_node_relation nr\n" +
               "	INNER JOIN risk_lunnan_test.ra_node n ON nr.node_id = n.id AND n.is_del = 0\n" +
               "WHERE nr.linked_type = 7;";
    }

    /**
     * 获取源数据SQL
     *
     * @return 源数据查询SQL
     */
    public String getSourceSql() {
        return "SELECT\n" +
               "  nr.id,\n" +
               "  n.tenant_id,\n" +
               "  nr.node_id,\n" +
               "  nr.linked_id\n" +
               "FROM\n" +
               "  risk_lunnan_test.ra_node_relation nr\n" +
               "	INNER JOIN risk_lunnan_test.ra_node n ON nr.node_id = n.id AND n.is_del = 0\n" +
               "WHERE nr.linked_type = 7;";
    }

    /**
     * 获取目标数据SQL模板
     *
     * @return 目标数据SQL模板
     */
    public String getTargetSqlTemplate() {
        return "INSERT INTO risk_device_step (\n" +
               "  id,\n" +
               "  department_id,\n" +
               "  device_id,\n" +
               "  step_id,\n" +
               "  deviation_id,\n" +
               "  cause_quantity,\n" +
               "  consequence_quantity\n" +
               ")";
    }
}
